<?php
	class MemberModel extends Model{
		public function dologin($data){
			$login_login = $data['login'];
			$login_pwd = $data['password'];
			$userinfo = D('member')->where('login = "'.$login_login.'"')->find();
			if(!empty($_SESSION['wxid'])){
					$dd['wx'] = $_SESSION['wxid'];
			}
			$dd['lastlogin'] = time();
			if(!empty($userinfo)){
				$login_pwd_md5 = md5(md5($login_pwd).$userinfo['login_salt']);
				if($login_pwd_md5==$userinfo['password']){
					//绑定账号
					$da = $this->where('login = "'.$login_login.'"')->save($dd);
					if($da){
						$this->_locallogin($userinfo['uid']);
						return true;
					}else{
						return false;
					}
					
				}else{
					return false;
				}
			}else{
				return false;
			}
		}
		
		public function _locallogin($uid){
			$userinfo = D('member')->where('uid = '.$uid)->find();
			$_SESSION['member'] = $userinfo;
			$this->setcookie();
			return true;
		}
		
		public function setcookie(){
			$cid = authcode($_SESSION['member']['uid'],'ENCODE');
			$time = time()+3600*24*365;
			cookie('rcwxuid',$cid,$time);
		}

	
	}
?>